using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region CustomerInfo

	/// <summary>
	/// CustomerInfo object for NHibernate mapped table 'CustomerInfo'.
	/// </summary>
	[Serializable]
	public class CustomerInfo : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _name;
		protected string _title;
		protected string _company;
		protected string _venue;
		protected string _country;
		protected bool _isFCPA;
		protected string _visitObjective;
		protected decimal _revenuePotential;
		protected int _potentialRevenueTimeframe;
		protected int _salesStage;
		protected bool _isInRFP;
		protected string _rFPDetail;
		protected bool _isSensitiveIssue;
		protected string _isThereSensitiveIssue;
		protected bool _isKeyMessage;
		protected string _isThereKeyMessage;
		protected string _companyProfile;
		protected string _proposalNo;
		protected string _numberOfPerson;
		protected Application _application;
		protected DicItem _accountType;
		protected IList _customerAttendees;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public CustomerInfo() { }

		public CustomerInfo( string name, string title, string company, string venue, string country, bool isFCPA, string visitObjective, decimal revenuePotential, int potentialRevenueTimeframe, int salesStage, bool isInRFP, string rFPDetail, bool isSensitiveIssue, string isThereSensitiveIssue, bool isKeyMessage, string isThereKeyMessage, string companyProfile, string proposalNo, string numberOfPerson, Application application, DicItem accountType )
		{
			this._name = name;
			this._title = title;
			this._company = company;
			this._venue = venue;
			this._country = country;
			this._isFCPA = isFCPA;
			this._visitObjective = visitObjective;
			this._revenuePotential = revenuePotential;
			this._potentialRevenueTimeframe = potentialRevenueTimeframe;
			this._salesStage = salesStage;
			this._isInRFP = isInRFP;
			this._rFPDetail = rFPDetail;
			this._isSensitiveIssue = isSensitiveIssue;
			this._isThereSensitiveIssue = isThereSensitiveIssue;
			this._isKeyMessage = isKeyMessage;
			this._isThereKeyMessage = isThereKeyMessage;
			this._companyProfile = companyProfile;
			this._proposalNo = proposalNo;
			this._numberOfPerson = numberOfPerson;
			this._application = application;
			this._accountType = accountType;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public string Title
		{
			get { return _title; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Title", value, value.ToString());
				_title = value;
			}
		}

		public string Company
		{
			get { return _company; }
			set
			{
				if ( value != null && value.Length > 200)
					throw new ArgumentOutOfRangeException("Invalid value for Company", value, value.ToString());
				_company = value;
			}
		}

		public string Venue
		{
			get { return _venue; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_venue = value;
			}
		}

		public string Country
		{
			get { return _country; }
			set
			{
				if ( value != null && value.Length > 100)
					value = value.Substring(0, 100 );
				_country = value;
			}
		}

		public bool IsFCPA
		{
			get { return _isFCPA; }
			set { _isFCPA = value; }
		}

		public string VisitObjective
		{
			get { return _visitObjective; }
			set
			{
				if ( value != null && value.Length > 1000)
					value = value.Substring(0, 1000 );
				_visitObjective = value;
			}
		}

		//TODO: encrypt, add by kevin
		public decimal RevenuePotential
		{
			get { return _revenuePotential; }
			set { _revenuePotential = value; }
		}

		public decimal DecryptedRevenuePotential
		{
			get { return EncryptHelper.Decrypt(_revenuePotential); }
			set { _revenuePotential = EncryptHelper.Encrypt(value); }
		}

		public int PotentialRevenueTimeframe
		{
			get { return _potentialRevenueTimeframe; }
			set { _potentialRevenueTimeframe = value; }
		}

		public int SalesStage
		{
			get { return _salesStage; }
			set { _salesStage = value; }
		}

		public bool IsInRFP
		{
			get { return _isInRFP; }
			set { _isInRFP = value; }
		}

		public string RFPDetail
		{
			get { return _rFPDetail; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_rFPDetail = value;
			}
		}

		public bool IsSensitiveIssue
		{
			get { return _isSensitiveIssue; }
			set { _isSensitiveIssue = value; }
		}

		public string IsThereSensitiveIssue
		{
			get { return _isThereSensitiveIssue; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_isThereSensitiveIssue = value;
			}
		}

		public bool IsKeyMessage
		{
			get { return _isKeyMessage; }
			set { _isKeyMessage = value; }
		}

		public string IsThereKeyMessage
		{
			get { return _isThereKeyMessage; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_isThereKeyMessage = value;
			}
		}

		public string CompanyProfile
		{
			get { return _companyProfile; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_companyProfile = value;
			}
		}

		public string ProposalNo
		{
			get { return _proposalNo; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_proposalNo = value;
			}
		}

		public string NumberOfPerson
		{
			get { return _numberOfPerson; }
			set
			{
				if ( value != null && value.Length > 10)
					throw new ArgumentOutOfRangeException("Invalid value for NumberOfPerson", value, value.ToString());
				_numberOfPerson = value;
			}
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public DicItem AccountType
		{
			get { return _accountType; }
			set { _accountType = value; }
		}

		public IList CustomerAttendees
		{
			get
			{
				if (_customerAttendees==null)
				{
					_customerAttendees = new ArrayList();
				}
				return _customerAttendees;
			}
			set { _customerAttendees = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is CustomerInfo))
				throw new InvalidCastException("This object is not of type CustomerInfo");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((CustomerInfo)obj).Id);
					break;
				case "Name":
						relativeValue = ( this.Name != null ) ? this.Name.CompareTo(((CustomerInfo)obj).Name) : -1;
					break;
				case "Title":
						relativeValue = ( this.Title != null ) ? this.Title.CompareTo(((CustomerInfo)obj).Title) : -1;
					break;
				case "Company":
						relativeValue = ( this.Company != null ) ? this.Company.CompareTo(((CustomerInfo)obj).Company) : -1;
					break;
				case "Venue":
						relativeValue = ( this.Venue != null ) ? this.Venue.CompareTo(((CustomerInfo)obj).Venue) : -1;
					break;
				case "Country":
						relativeValue = ( this.Country != null ) ? this.Country.CompareTo(((CustomerInfo)obj).Country) : -1;
					break;
				case "IsFCPA":
					relativeValue = this.IsFCPA.CompareTo(((CustomerInfo)obj).IsFCPA);
					break;
				case "VisitObjective":
						relativeValue = ( this.VisitObjective != null ) ? this.VisitObjective.CompareTo(((CustomerInfo)obj).VisitObjective) : -1;
					break;
				case "RevenuePotential":
					relativeValue = this.DecryptedRevenuePotential.CompareTo(((CustomerInfo)obj).DecryptedRevenuePotential);
					break;
				case "PotentialRevenueTimeframe":
					relativeValue = this.PotentialRevenueTimeframe.CompareTo(((CustomerInfo)obj).PotentialRevenueTimeframe);
					break;
				case "SalesStage":
					relativeValue = this.SalesStage.CompareTo(((CustomerInfo)obj).SalesStage);
					break;
				case "IsInRFP":
						relativeValue = ( this.IsInRFP != Convert.ToBoolean( null) ) ? this.IsInRFP.CompareTo(((CustomerInfo)obj).IsInRFP) : -1;				
					break;
				case "RFPDetail":
						relativeValue = ( this.RFPDetail != null ) ? this.RFPDetail.CompareTo(((CustomerInfo)obj).RFPDetail) : -1;
					break;
				case "IsSensitiveIssue":
						relativeValue = ( this.IsSensitiveIssue != Convert.ToBoolean( null) ) ? this.IsSensitiveIssue.CompareTo(((CustomerInfo)obj).IsSensitiveIssue) : -1;				
					break;
				case "IsThereSensitiveIssue":
						relativeValue = ( this.IsThereSensitiveIssue != null ) ? this.IsThereSensitiveIssue.CompareTo(((CustomerInfo)obj).IsThereSensitiveIssue) : -1;
					break;
				case "IsKeyMessage":
						relativeValue = ( this.IsKeyMessage != Convert.ToBoolean( null) ) ? this.IsKeyMessage.CompareTo(((CustomerInfo)obj).IsKeyMessage) : -1;				
					break;
				case "IsThereKeyMessage":
						relativeValue = ( this.IsThereKeyMessage != null ) ? this.IsThereKeyMessage.CompareTo(((CustomerInfo)obj).IsThereKeyMessage) : -1;
					break;
				case "CompanyProfile":
						relativeValue = ( this.CompanyProfile != null ) ? this.CompanyProfile.CompareTo(((CustomerInfo)obj).CompanyProfile) : -1;
					break;
				case "ProposalNo":
						relativeValue = ( this.ProposalNo != null ) ? this.ProposalNo.CompareTo(((CustomerInfo)obj).ProposalNo) : -1;
					break;
				case "NumberOfPerson":
						relativeValue = ( this.NumberOfPerson != null ) ? this.NumberOfPerson.CompareTo(((CustomerInfo)obj).NumberOfPerson) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (CustomerInfo.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
